<h1><code ng:non-bindable="">limitTo</code>
<span class="hint">(filter in module <code ng:non-bindable="">ng</code>
)</span>
</h1>
<div><h2 id="Description">Description</h2>
<div class="description"><p>Creates a new array containing only a specified number of elements in an array. The elements
are taken from either the beginning or the end of the source array, as specified by the
value and sign (positive or negative) of <code>limit</code>.</p>

<p>Note: This function is used to augment the <code>Array</code> type in Angular expressions. See
<a href="api/ng.$filter"><code>ng.$filter</code></a> for more information about Angular arrays.</p></div>
<h2 id="Usage">Usage</h2>
<div class="usage"><pre class="prettyprint linenums">filter:limitTo(array, limit);</pre>
<h3 id="Parameters">Parameters</h3>
<ul class="parameters"><li><code ng:non-bindable="">array – {Array} – </code>
<p>Source array to be limited.</p></li>
<li><code ng:non-bindable="">limit – {string|Number} – </code>
<p>The length of the returned array. If the <code>limit</code> number is
positive, <code>limit</code> number of items from the beginning of the source array are copied.
If the number is negative, <code>limit</code> number  of items from the end of the source array are
copied. The <code>limit</code> will be trimmed if it exceeds <code>array.length</code></p></li>
</ul>
<h3 id="Returns">Returns</h3>
<div class="returns"><code ng:non-bindable="">{Array}</code>
– <p>A new sub-array of length <code>limit</code> or less if input array had less than <code>limit</code>
elements.</p></div>
</div>
<h2 id="Example">Example</h2>
<div class="example"><h4>Source</h4>
<div source-edit="" source-edit-deps="angular.js script.js" source-edit-html="index.html-203" source-edit-css="" source-edit-js="script.js-202" source-edit-unit="" source-edit-scenario="scenario.js-204"></div>
<div class="tabbable"><div class="tab-pane" title="index.html">
<pre class="prettyprint linenums" ng-set-text="index.html-203" ng-html-wrap=" angular.js script.js"></pre>
<script type="text/ng-template" id="index.html-203">
  
  <div ng-controller="Ctrl">
    Limit {{numbers}} to: <input type="integer" ng-model="limit">
    <p>Output: {{ numbers | limitTo:limit }}</p>
  </div>
</script>
</div>
<div class="tab-pane" title="script.js">
<pre class="prettyprint linenums" ng-set-text="script.js-202"></pre>
<script type="text/ng-template" id="script.js-202">
    function Ctrl($scope) {
      $scope.numbers = [1,2,3,4,5,6,7,8,9];
      $scope.limit = 3;
    }
  </script>
</div>
<div class="tab-pane" title="End to end test">
<pre class="prettyprint linenums" ng-set-text="scenario.js-204"></pre>
<script type="text/ng-template" id="scenario.js-204">
  it('should limit the numer array to first three items', function() {
    expect(element('.doc-example-live input[ng-model=limit]').val()).toBe('3');
    expect(binding('numbers | limitTo:limit')).toEqual('[1,2,3]');
  });

  it('should update the output when -3 is entered', function() {
    input('limit').enter(-3);
    expect(binding('numbers | limitTo:limit')).toEqual('[7,8,9]');
  });

  it('should not exceed the maximum size of input array', function() {
    input('limit').enter(100);
    expect(binding('numbers | limitTo:limit')).toEqual('[1,2,3,4,5,6,7,8,9]');
  });
</script>
</div>
</div><h4>Demo</h4>
<div class="well doc-example-live" ng-embed-app="" ng-set-html="index.html-203" ng-eval-javascript="script.js-202"></div></div>
</div>
